package com.sg.java.util;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.apache.commons.lang3.StringUtils;

public class JSONUtils {

    private static final Gson gson = new Gson();

    public static Gson getInstance() {
        return gson;
    }

    public static String toJson(Object src) {
        return gson.toJson(src);
    }

    public static <T> T fromJson(String json, Class<T> typeOfT) {
        return gson.fromJson(json, typeOfT);
    }

    public static JsonObject toJsonObject(String json) {
        return gson.fromJson(json, JsonObject.class);
    }

    public static boolean jsonElementIsNotBlank(JsonElement je) {
        return je != null && StringUtils.isNotBlank(je.getAsString());
    }

}
